package zfzAI;
import java.awt.Point;


public class CGameMap {
public int width,height;
private int[][] map;
private static int[][] way={{-1,0},{-1,-1},{0,-1},{1,-1},{-1,1},{0,1},{1,1},{1,0}};
public CGameMap()
{
	width=15;
	height=15;
	map=new int[width][];
	for(int i=0;i<width;++i)
	{
		map[i]=new int[height];
		for(int o=0;o<height;++o)
			map[i][o]=-1;
	}
}
public boolean inMap(int x,int y)
{
	return x>0&&x<width&&y>0&&y<height;
}
public int OnColor(int x,int y)
{
	return map[x][y];
}
public int getP(int x,int y)
{
	if(x<0||x>=width||y<0||y>=height) return -2;
	return map[x][y];
}
public boolean setP(int x,int y,int color)
{
	if(x<0||x>=width||y<0||y>=height) return false;
	map[x][y]=color;
	return true;
}
public boolean isHeWin(int color)
{
	for(int i=0;i<width;++i)
		for(int o=0;o<height;++o)
			if(map[i][o]==color)
				for(int p=0;p<8;++p)
				{
					int x1=i,y1=o,len=1;
					while(getP(x1, y1)==color)
					{
						x1+=way[p][0];
						y1+=way[p][1];
						++len;
					}
					if(len>5)
						return true;
				}
	return false;
}
public void showMap() {
	for (int i=0; i<width; ++i) {
		for (int j=0; j<height; ++j)
			System.out.print(map[i][j]);
		System.out.println();
	}
}
public int[][] getBoard() {
	int[][] board = new int[15][15];
	for (int i=0; i<15; ++i)
		for (int j=0; j<15; ++j)
			if (map[i][j] == -1) board[i][j] = 42;
			else if (map[i][j] == 0) board[i][j] = 0;
			else if (map[i][j] == 1) board[i][j] = 1;
	return board;
}
}
